import request from '../utils/request.js'

/**
 * 登录
 * @param data
 * @returns {*}
 */
export const login = (data) => {
  return request({
    url: '/shell/SysLogin',
    method: 'post',
    data
  })
}

/**
 /**
 * 登录时发送短信验证码
 * @param data
 * @returns {*}
 */
export const sendLoginCheckCode = (data) => {
  return request({
    url: '/shell/SendLoginCheckCode',
    method: 'post',
    data
  })
}

/**
 * 创建本机构子账号，当前用户必须为主账号。需认证
 * @param data
 * @returns {*}
 */
export const createSubUser = (data) => {
  return request({
    url: '/shell/CreateSubUser',
    method: 'post',
    data
  })
}

export const getCheckCodeImage = (data) => {
  return request({
    url: '/shell/GetCheckCodeImage',
    method: 'post',
    data
  })
}

/**
 * 退出登录
 * @param data
 * @returns {*}
 */
export const logoutApi = () => {
  return request({
    url: '/shell/SysLogout',
    method: 'post'
  })
}

/**
 * 获取当前用户信息
 * @param data
 * @returns {*}
 */
export const getCurrentUser = (data) => {
  return request({
    url: '/shell/GetCurrentUser',
    method: 'post',
    data
  })
}

/**
 * 获取用户列表
 * @param data
 * @returns {*}
 */
export const getUserListApi = (data) => {
  return request({
    url: '/shell/GetUserList',
    method: 'post',
    data
  })
}
/**
 * 新增或更新用户
 * @param data
 * @returns {*}
 */
export const createOrUpdateUserApi = (data) => {
  return request({
    url: '/shell/CreateOrUpdateUser',
    method: 'post',
    data
  })
}
/**
 * 变更用户状态
 * @param data
 * @returns {*}
 */
export const setUserStatusApi = (data) => {
  return request({
    url: '/shell/SetUserStatus',
    method: 'post',
    data
  })
}

/**
 * 获取部门列表
 * @param data
 * @returns {*}
 */
export const getDeptListApi = (data) => {
  return request({
    url: '/shell/GetDepartmentList',
    method: 'post',
    data
  })
}

/**
 * 创建或修改部门
 * @param data
 * @returns {*}
 */
export const createOrUpdateDepartmentApi = (data) => {
  return request({
    url: '/shell/CreateOrUpdateDepartment',
    method: 'post',
    data
  })
}
/**
 * 修改部门状态
 * @param data
 * @returns {*}
 */
export const setDepartmentStatusApi = (data) => {
  return request({
    url: '/shell/SetDepartmentStatus',
    method: 'post',
    data
  })
}
/**
 * 重置用户密码
 * @param data
 * @returns {*}
 */
export const resetPasswordApi = (data) => {
  return request({
    url: '/shell/resetPassword',
    method: 'post',
    data
  })
}

/**
 * 删除用户
 * @param data
 * @returns {*}
 */
export const deleteSubUser = (data) => {
  return request({
    url: '/shell/DeleteSubUser',
    method: 'post',
    data
  })
}

/**
 * 设置用户密码
 * @param data
 * @returns {*}
 */
export const setPasswordApi = (data) => {
  return request({
    url: '/shell/SetPassword',
    method: 'post',
    data
  })
}
/**
 * 设置用户密码(新用户或者密码过期设置自己的密码)
 * @param data
 * @returns {*}
 */
export const setPasswordWithoutCheckAccessTokenApi = (data) => {
  return request({
    url: '/shell/SetPasswordWithoutCheckAccessToken',
    method: 'post',
    data
  })
}

/**
 * 下载文件
 * @param fid
 * @returns {*}
 */
export const downLoadFile = (fid) => {
  return request({
    url: `/shell/GetFile`,
    method: 'get',
    responseType: 'blob',
    params: { fid }
  })
}

/**
 * 上传文件
 * @param data
 * @param id
 * @returns {*}
 */
export const fileUpload = (data, id, type) => {
  return request({
    url: `/shell/FileUpload?id=${id}&ftype=${type}`,
    method: 'post',
    headers: {
      'Content-Type': 'multipart/form-data;charset=UTF-8'
    },
    data
  })
}
